<?php
//yc@2009-10-24 20:09:47

class Setting extends Model
{
    private $db;
    private $config = array();
    public function __construct()
    {
        $this->db = loadLib('DbMysql');    
    }

    public function getAllConfig()
    {
        $c = $this->db->fetchAll('SELECT * FROM config WHERE 1=1');
        if(!empty($c)){
            foreach($c as $d)
                $this->config[$d['name']] = array($d['value'], $d['description']);
        }
        return $this->config;
    }

    public function getConfig($name)
    {
        if (!isset($this->config[$name]))
            $this->getAllConfig();
        return $this->config[$name][0];
    }

    public function update($name, $value)
    {
        $name = clearSlashes($name);
        if (isset($this->config[$name]))
            $this->config[$name][0] = $value;
        $this->db->update('config', array('value' => $value), 'name="' . $name . '"');
    }
}
?>
